package com.sagframe.sagacity.sqltoy.plus.multi.model;

import com.sagframe.sagacity.sqltoy.plus.conditions.eumn.SqlFunctionEnum;
import com.sagframe.sagacity.sqltoy.plus.conditions.interfaces.SFunction;

public class StrColumn {

    private String column;

    private SqlFunctionEnum sqlFunctionEnum;

    private String asName;

    private StrColumn(String column) {
        this.column = column;
    }

    public StrColumn(String column, SqlFunctionEnum sqlFunctionEnum) {
        this.column = column;
        this.sqlFunctionEnum = sqlFunctionEnum;
    }

    public static <T> StrColumn of(String column) {
        return new StrColumn(column);
    }

    public static <T> StrColumn avg(String column) {
        return new StrColumn(column, SqlFunctionEnum.AVG);
    }

    public static <T> StrColumn count(String column) {
        return new StrColumn(column, SqlFunctionEnum.COUNT);
    }

    public static <T> StrColumn sum(String column) {
        return new StrColumn(column, SqlFunctionEnum.SUM);
    }

    public static <T> StrColumn min(String column) {
        return new StrColumn(column, SqlFunctionEnum.MIN);
    }

    public static <T> StrColumn max(String column) {
        return new StrColumn(column, SqlFunctionEnum.MAX);
    }

    public static <T> StrColumn distinct(String column) {
        return new StrColumn(column, SqlFunctionEnum.DISTINCT);
    }

    public StrColumn as(String name) {
        this.asName = name;
        return this;
    }

    public String getColumn() {
        return column;
    }

    public SqlFunctionEnum getSqlFunctionEnum() {
        return sqlFunctionEnum;
    }

    public String getAsName() {
        if (asName == null || asName.isEmpty()) {
            return "";
        }
        return " AS " + asName;
    }
}
